package org.openharmony.qttool.components;

import org.openharmony.qttool.QtSDK;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class HarmonyQtComboBoxWithBrowseButton extends ComponentWithBrowseButton<HarmonyQtComboBox> {
    public HarmonyQtComboBoxWithBrowseButton(HarmonyQtComboBox comboBox) {
        super(comboBox, null);
        setIcon();
    }

    public HarmonyQtComboBoxWithBrowseButton(ComboBoxModel<QtSDK> model) {
        super(new HarmonyQtComboBox(model), null);
        setIcon();
    }

    public QtSDK getSelectedItem() {
        HarmonyQtComboBox comboBox = getChildComponent();
        return (QtSDK) comboBox.getSelectedItem();
    }

    private void setIcon() {
        ClassLoader classLoader = getClass().getClassLoader();

        URL imageUrl = classLoader.getResource("images/setting.png");
        if (imageUrl != null) {
            ImageIcon icon = new ImageIcon(imageUrl);
            Image scaledImage = icon.getImage().getScaledInstance(16, 16, Image.SCALE_SMOOTH);
            ImageIcon scaledIcon = new ImageIcon(scaledImage);
            setButtonIcon(scaledIcon);
        }
    }
}
